package com.escom.utils;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.escom.R;
import com.escom.healthlc.entidad.TemperaturaORM;

import java.util.List;

/**
 * Created by Carlos on 22/04/2014.
 */
public class CustomTemperaturaAdapter extends ArrayAdapter<TemperaturaORM> {

    private Context context;
    private List<TemperaturaORM> drawerItemTemperatura;
    private int resource;

    public CustomTemperaturaAdapter(Context context, int resource, List<TemperaturaORM> drawerItemTemperatura) {
        super(context, resource, drawerItemTemperatura);
        this.context = context;
        this.drawerItemTemperatura = drawerItemTemperatura;
        this.resource = resource;
    }

    private static class TemperaturaViewHolder {
        TextView tVTemperaturaTemp;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TemperaturaViewHolder temperaturaViewHolder;
        View view = convertView;

        if (view == null) {
            LayoutInflater inflater = ((Activity) context).getLayoutInflater();
            view = inflater.inflate(resource, parent, false);
            temperaturaViewHolder = new TemperaturaViewHolder();
            temperaturaViewHolder.tVTemperaturaTemp = (TextView) view.findViewById(R.id.tVTemperaturaTemp);
            view.setTag(temperaturaViewHolder);
        } else {
            temperaturaViewHolder = (TemperaturaViewHolder) view.getTag();
        }

        TemperaturaORM temperatura = drawerItemTemperatura.get((drawerItemTemperatura.size() - 1) - position);
        temperaturaViewHolder.tVTemperaturaTemp.setText("Temperatura: " + temperatura.getTemp() + " °C");

        return view;
    }

    public void setDrawerItemTemperatura(List<TemperaturaORM> drawerItemTemperatura) {
        this.drawerItemTemperatura = drawerItemTemperatura;
    }
}
